const log4js = require('log4js')
log4js.configure({
    appenders: { cheese: { type: "file", filename: "cheese.log" } },
    categories: { default: { appenders: ["cheese"], level: "error" } }
  });

const logger = log4js.getLogger('cheese')
logger.level = 'debug'

const http = require('http')
const queryString = require('querystring')

const server = http.createServer((req, res)=>{
    // logger.debug(req)
    let data = ''
    req.on('data', chunk=>{
        data += chunk
    })
    req.on('end', ()=>{
        res.writeHead(200, {
            'content-type': 'text/html'
        })
        logger.debug(data)
        res.write(JSON.stringify(queryString.parse(data)))
        res.end()
        
    })
})

server.listen(8080, ()=>{
    console.log('localhost:8080')
})